package aod.android.com.bernay.message.fragment;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;
import com.zhy.adapter.recyclerview.wrapper.EmptyWrapper;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import aod.android.com.bernay.R;
import aod.android.com.bernay.base.BernayBaseFragment;
import aod.android.com.bernay.http.BernayApi;
import aod.android.com.bernay.http.BernayCallback;
import aod.android.com.bernay.mine.module.MineUserInfo;
import aod.android.com.bernay.util.MessageEvent;
import aod.android.com.bernay.util.SharePreUtils;
import chen.lion.hilib.util.LogUtils;
import chen.lion.hilib.view.bind.HiView;

/**
 * @author crated by zhixianuanyang on 2019/4/4 15:28
 * @Email jamesKing0812@gmail.com
 */
public class SystemMessageFragment extends BernayBaseFragment implements SwipeRefreshLayout.OnRefreshListener {

    @HiView(R.id.swipeRefreshLayout)
    SwipeRefreshLayout swipeRefreshLayout;

    @HiView(R.id.recyclerView)
    RecyclerView mRecyclerView;

    private CommonAdapter<String> mAdapter;
    EmptyWrapper  mEmptyWrapper;
    List<String> mDatas = new ArrayList<String>();

    //页
    private static final int pageIndex = 1;
    //一页条数
    private static final int pageSize = 10;

    //1是系统消息
    private static final int MSG_SYSTEM_TYPE = 1;

    @Override
    protected int initLayout() {
        return R.layout.fragment_system_message;
    }

    @Override
    protected void initData() {
        getUserMsg();
        for (int i = 0;i < 10;i ++){
            mDatas.add(i+"消息");
        }
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mAdapter = new CommonAdapter<String>(getActivity(),R.layout.system_message_list,mDatas) {
             @Override
             protected void convert(ViewHolder holder, String s, int position) {

             }
         };
        mRecyclerView.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {

            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });

    }


    /**
     * 获取用户信息
     */
    public void getUserMsg() {
        BernayApi.http().getUserMsg(pageIndex, pageSize, MSG_SYSTEM_TYPE, new BernayCallback() {
            @Override
            public void onJsonData(String json) {
                LogUtils.e(json);
            }

            @Override
            public void onHttpFailure(IOException e) {

            }
        });
    }



    private void initEmptyView(){
        mEmptyWrapper = new EmptyWrapper(mAdapter);
        mEmptyWrapper.setEmptyView(LayoutInflater.from(getActivity()).inflate(R.layout.empty_recycle_view, mRecyclerView, false));
    }

    @Override
    public void onRefresh() {
        swipeRefreshLayout.setEnabled(false);
    }
}
